package cn.stylefeng.guns.modular.basic.controller;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.http.HttpRequest;
import cn.stylefeng.guns.base.shiro.annotion.Permission;
import cn.stylefeng.guns.modular.basic.entity.*;
import cn.stylefeng.guns.modular.basic.model.params.BasicCustomerParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicXlbOauth2tokenParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicAreaResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicCustomerResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicWarehouseResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicXlbOauth2tokenResult;
import cn.stylefeng.guns.modular.basic.service.*;
import cn.stylefeng.guns.modular.hx.basic.entity.HxBasicGoods;
import cn.stylefeng.guns.modular.hx.basic.entity.HxBasicPositionGoods;
import cn.stylefeng.guns.modular.hx.basic.model.params.HxBasicGoodsParam;
import cn.stylefeng.guns.modular.hx.basic.model.result.HxBasicGoodsResult;
import cn.stylefeng.guns.modular.hx.basic.service.HxBasicGoodsService;
import cn.stylefeng.guns.modular.hx.basic.service.HxBasicPositionGoodsService;
import cn.stylefeng.guns.modular.hx.order.entity.HxOrderPut;
import cn.stylefeng.guns.modular.hx.order.entity.HxOrderPutDetailed;
import cn.stylefeng.guns.modular.hx.order.model.params.HxOrderPutDetailedParam;
import cn.stylefeng.guns.modular.hx.order.model.params.HxOrderPutParam;
import cn.stylefeng.guns.modular.hx.storage.entity.HxStorageStock;
import cn.stylefeng.guns.modular.hx.storage.service.HxStorageStockService;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.QRCodeUtil;
import cn.stylefeng.guns.modular.basic.model.params.BasicAreaParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicPositionParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicPutgoodsParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicPositionResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicPutgoodsResult;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;

/**
 * 库位表控制器
 */
@Controller
@RequestMapping("/basicPosition")
public class BasicPositionController extends BaseController {

    private String PREFIX = "/basic/basicPosition";

    @Autowired
    private BasicPositionService basicPositionService;

    @Autowired
    private UserService userService;

    @Autowired
    private BasicAreaService basicAreaService;

    @Autowired
    private BasicWarehouseService basicWarehouseService;

    @Autowired
    private BasicCustomerService basicCustomerService;

    @Autowired
    private BasicXlbOauth2tokenService basicXlbOauth2tokenService;
    @Autowired
    private HxBasicGoodsService hxBasicGoodsService;
    @Autowired
    private HxBasicPositionGoodsService hxBasicPositionGoodsService;

    /**
     * 去批量打印页面
     */
    @RequestMapping("/tobtnqrCode2")
    public String tobtnqrCode2() {
        return PREFIX + "/btnqrCode2.html";
    }

    /**
     * 去批量打印页面
     */
    @RequestMapping("/tobtnGoodsPositionCode")
    public String tobtnGoodsPositionCode() {
        return PREFIX + "/btnGoodsPositionCode.html";
    }

    /**
     * 查询user
     */
    @RequestMapping("/getuser")
    @ResponseBody
    public ResponseData getuser(String account) {
    	User user = userService.lambdaQuery().eq(User::getAccount, account).one();
        return ResponseData.success(user);
    }

    /**
     * 去批量打印页面
     */
    @RequestMapping("/tobtnqrCode")
    public String tobtnqrCode() {
        return PREFIX + "/btnqrCode.html";
    }

    /**
     * 选择商品页面
     */
    @RequestMapping("/toChoiceGoods")
    public String toChoiceGoods(Model model) {
    	User user = userService.getcurrentUser();
    	//查询可选择客户
    	model.addAttribute("customerlist", basicCustomerService.findAvailableList(user.getDeptId(),user.getDeliverId(),user.getOperateId()));
        return PREFIX + "/choiceGoods.html";
    }

    /**
     * 选择库位页面hx
     */
    @RequestMapping("/tochoicePositionHx")
    public String tochoicePositionHx() {
        return PREFIX + "/choicePositionHx.html";
    }

    /**
     * 同步新零帮库位页面
     */
    @RequestMapping("/pickWarehouse")
    public String pickWarehouse(Model model) {
        User user = userService.getcurrentUser();
        Long deptId = user.getDeptId();
        Long deliverId = user.getDeliverId();
        model.addAttribute("basicCustomerList", basicCustomerService.findAvailableList(deptId,deliverId,user.getOperateId()));
//查询可选择仓库
        model.addAttribute("basicWarehouseList", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));


        return PREFIX + "/pickWarehouseXlb.html";
    }




    /**
     * 同步新零帮库位接口
     *
     * @author
     * @Date 2024-04-17
     */
    @RequestMapping("/findArea")
    @ResponseBody
    @Permission
    public ResponseData findArea(Long setWarehouseId,Integer customerId) {
        User user = userService.getcurrentUser();
        BasicWarehouse w = basicWarehouseService.getById(setWarehouseId);
        BasicCustomer r = basicCustomerService.getById(customerId);
        if(ToolUtil.isEmpty(w.getWarehouseXlbId())) {
            return ResponseData.error("请维护新零帮仓库id");
        }
        if(ToolUtil.isEmpty(r.getGsnumber())) {
            return ResponseData.error("请维护新零帮公司号");
        }

//      String url = "https://test-api.xlbsoft.com/api/hxl.open.wms.storage.findbystorehouseId";
        String url = "https://hxl-api.xlbsoft.com/api/hxl.open.wms.storage.findbystorehouseId";
        JSONObject json = new JSONObject();
        json.put("storehouse_id", w.getWarehouseXlbId());
        BasicXlbOauth2tokenParam oauth2tokenParam = new BasicXlbOauth2tokenParam();
        oauth2tokenParam.setDeliverId(r.getDeliverId());
        oauth2tokenParam.setGsnumber(r.getGsnumber());
        BasicXlbOauth2tokenResult oauth2tokenResult = basicXlbOauth2tokenService.findBySpec(oauth2tokenParam);
        String response = HttpRequest.post(url)
                .header("Authorization", "Bearer "+oauth2tokenResult.getOauth2TokenXlb())
                .body(json.toString()).execute().body();
        JSONObject jsonObject = new JSONObject(response);
        if (jsonObject.get("code").toString().equals("0")) {
            JSONArray dataArray = jsonObject.getJSONArray("data");
            List<BasicPosition> basicPositionList = new ArrayList<>(); // 用于存储每一页的数据，批量添加到系统中
            List<HxBasicPositionGoods> hxBasicPositionGoodsList = new ArrayList<>(); // 用于存储每一页的数据，批量添加到系统中

			Map<String, BasicAreaResult> areaMap = new HashMap<>();
			BasicAreaParam areap = new BasicAreaParam();
			areap.setAreaWarehouseId(w.getId());
			List<BasicAreaResult> hxp = basicAreaService.findListBySpec(areap,null,null);
			for (BasicAreaResult pr : hxp) {
				areaMap.put(pr.getAreaName(), pr);
			}
            for (Object data : dataArray) {
                BasicPosition  basicPositionParam = new BasicPosition();
                basicPositionParam.setPositionState("1");
                HxBasicPositionGoods basicPositionGoodsParam = new HxBasicPositionGoods();
                Object attribute = ((JSONObject) data).get("attribute");// 库位属性
                Object categoryId = ((JSONObject) data).get("category_id");// 分类id
                Object categoryName = ((JSONObject) data).get("category_name");//库位分类名称
                Object code = ((JSONObject) data).get("code");// 库位代码
                Object companyId = ((JSONObject) data).get("company_id");// 公司id
                Object id = ((JSONObject) data).get("id");// 库位id
                Object name = ((JSONObject) data).get("name");// 库位名称
                Object regionName = ((JSONObject) data).get("region_name");// 库位区域名称
                Object storehouseId = ((JSONObject) data).get("storehouse_id");// 仓库id
                Object storehouseName = ((JSONObject) data).get("storehouse_name");// 仓库名称
                basicPositionParam.setPositionXlbId(id.toString());
                basicPositionParam.setWarehouseId(w.getId());
                basicPositionParam.setWarehouseName(w.getWarehouseName());
                basicPositionParam.setWarehouseNumber(w.getWarehouseNumber());
                basicPositionParam.setPositionAreaName(String.valueOf(regionName));
                BasicAreaResult  area = areaMap.get(regionName);
                if (ToolUtil.isNotEmpty(area)){
                    basicPositionParam.setPositionAreaId(area.getId());
                }
                if (ToolUtil.isNotEmpty(area)){
                    basicPositionParam.setAreaNumber(area.getAreaNumber());
                }

                if (attribute.toString().equals("STORAGER")){
                    basicPositionParam.setPositionType("存储位");
                }
                if (attribute.toString().equals("PICK")){
                    basicPositionParam.setPositionType("拣货位");
                }
                if (attribute.toString().equals("DISTRIBUTION")){
                    continue;
                }
                if (attribute.toString().equals("PROVISIONAL")){
                    continue;
                }
                basicPositionParam.setPositionNumber(name.toString());
//                Integer basicPosition = basicPositionService.lambdaQuery()
//                        .eq(BasicPosition::getPositionNumber, name.toString())
//                        .eq(BasicPosition::getWarehouseId, goodsid.getId())
//                        .count();
//                if (basicPosition >0) {
//                    continue; // 库位已存在，跳过
//                }

                basicPositionParam.setDeliverId(user.getDeliverId());
                basicPositionParam.setDeptId(user.getDeptId());
                basicPositionParam.setTraySize("1");
                basicPositionList.add(basicPositionParam);

//查询库位接口中，返回库位，商品信息，安全库存值。然后导入库位的时候，同步到库位商品绑定关系表，同时更新商品的安全库存值。
                // 同步到库位商品绑定关系表
//                basicPositionGoodsParam.setPositionId((long)area.getId());
//                basicPositionGoodsParam.setPositionNumber(code.toString());
//                basicPositionGoodsParam.setGoodsName("");
//                basicPositionGoodsParam.setGoodsId(0L);
//                basicPositionGoodsParam.setGoodsName("");
//                basicPositionGoodsParam.setGoodsPcode69("");
//                basicPositionGoodsParam.setGoodsNumber("");
//                basicPositionGoodsParam.setGoodsSpecs("");
//                basicPositionGoodsParam.setAnquanNum("");
//                hxBasicPositionGoodsList.add(basicPositionGoodsParam);
//                hxBasicGoodsService.lambdaUpdate()
//                        .eq(HxBasicGoods::getGoodsXlbId, "查回来的新零帮商品id")
//                        .set(HxBasicGoods::getAnquanNum, "新零帮商品安全库存值")
//                        .update();

                if(basicPositionList.size()>=2000){
                    basicPositionService.saveBatch(basicPositionList);
                    basicPositionList.clear();
                }
            }
//          hxBasicPositionGoodsService.saveBatch(hxBasicPositionGoodsList);
            if(basicPositionList.size()>0){
                basicPositionService.saveBatch(basicPositionList);
                basicPositionList.clear();
            }
        }
        return ResponseData.success();
    }




    /**
     * 创建二维码
     */
    @RequestMapping(value = "/getqrcode", method = RequestMethod.GET)
    @ResponseBody
    public void generateQRCode4Product(String id,String name, HttpServletRequest request, HttpServletResponse response) {
        try {
            //logo
            File logoFile = new File("");
            String url = id;
            QRCodeUtil.drawLogoCode_128(logoFile, url, name,720,350,request,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();

    	//查询可选择仓库
    	model.addAttribute("wlist", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/basicPosition.html";
    }

    /**
     * 跳转到主页面
     */
    @RequestMapping("index_hx")
    public String index_hx(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();

    	//查询可选择仓库
    	model.addAttribute("wlist", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/basicPosition_hx.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();

    	//查询可选择仓库
    	model.addAttribute("wlist", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/basicPosition_add.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add_hx")
    public String add_hx(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();

    	//查询可选择仓库
    	model.addAttribute("wlist", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/basicPosition_add_hx.html";
    }

    /**
     * 导入页面
     */
    @RequestMapping("/toimportExcel")
    public String toimportExcel(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();

    	//查询可选择仓库
    	model.addAttribute("wlist", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/import.html";
    }

    /**
     * 导入页面
     */
    @RequestMapping("/toimportExcelUpadate")
    public String toimportExcelUpadate(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();

    	//查询可选择仓库
    	model.addAttribute("wlist", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/importUpdate.html";
    }

    /**
     * 下载模板
     * @throws ServletException , IOException
     */
    @RequestMapping("downloadExcel")
    public void downloadExcel(HttpServletRequest request,HttpServletResponse response) throws ServletException ,IOException {
        String path = "assets/excel/position.xlsx";
        try {
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path);
            OutputStream  outputStream = response.getOutputStream();
            //设置下载的文件类型
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            //设置下载文件名
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(("Warehouse Position Template" + ".xlsx").getBytes(), "iso-8859-1"));
            IOUtils.copy(inputStream, outputStream);
            outputStream.flush();
            inputStream.close();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 导入excel
     */
	@RequestMapping(value = "/importExcel" , method = {RequestMethod.POST} )
    @ResponseBody
    public ResponseData importExceNewmethodl(@RequestPart("file") MultipartFile file,  BasicPositionParam basicPositionParam)  {
		ResponseData data = new ResponseData();
		try {
			data = basicPositionService.getExceldata(file,basicPositionParam,data);//处理导入数据
		} catch (Exception e) {
			data.setSuccess(false);
			e.printStackTrace();
		}
        return data;
    }

    /**
     * 导入excel
     */
	@RequestMapping(value = "/importExcelUpdate" , method = {RequestMethod.POST} )
    @ResponseBody
    public ResponseData importExceNewmethodlUpdate(@RequestPart("file") MultipartFile file,  BasicPositionParam basicPositionParam)  {
		ResponseData data = new ResponseData();
		try {
			data = basicPositionService.getExceldataUpdate(file,basicPositionParam,data);//处理导入数据
		} catch (Exception e) {
			data.setSuccess(false);
			e.printStackTrace();
		}
        return data;
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit(BasicPositionParam basicPositionParam,Model model) {
    	BasicPosition basicPosition = basicPositionService.getById(basicPositionParam.getId());
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();

    	//查询可选择仓库
    	model.addAttribute("wlist", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));

    	BasicAreaParam basicAreaParam = new BasicAreaParam();
    	basicAreaParam.setAreaWarehouseId(basicPosition.getWarehouseId());
    	basicAreaParam.setDeliverId(deliverId);
    	model.addAttribute("alist",basicAreaService.findListBySpec(basicAreaParam, deptId,user.getOperateId()));
        return PREFIX + "/basicPosition_edit.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit_hx")
    public String edit_hx(BasicPositionParam basicPositionParam,Model model) {
    	BasicPosition basicPosition = basicPositionService.getById(basicPositionParam.getId());
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();

    	//查询可选择仓库
    	model.addAttribute("wlist", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));

    	BasicAreaParam basicAreaParam = new BasicAreaParam();
    	basicAreaParam.setAreaWarehouseId(basicPosition.getWarehouseId());
    	basicAreaParam.setDeliverId(deliverId);
    	model.addAttribute("alist",basicAreaService.findListBySpec(basicAreaParam, deptId,user.getOperateId()));
        return PREFIX + "/basicPosition_edit_hx.html";
    }

    /**
     * 修改坐标页面
     */
    @RequestMapping("/toeditCoordinate")
    public String toeditCoordinate(Model model) {
        return PREFIX + "/edit_Coordinate.html";
    }

    /**
     * 新增接口
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BasicPositionParam basicPositionParam) {
    	Object positionAreaId = basicPositionParam.getPositionAreaId();
    	if (positionAreaId!=null) {
			BasicArea bawBasicArea = basicAreaService.getById(Integer.parseInt(positionAreaId.toString()));
			basicPositionParam.setPositionAreaName(bawBasicArea.getAreaName());//库区名称
			basicPositionParam.setAreaNumber(bawBasicArea.getAreaNumber());
			basicPositionParam.setPositionFunction(bawBasicArea.getAreaFunction());//库区功能
			basicPositionParam.setPositionAreaType(bawBasicArea.getAreaType());//库区类型
		}
    	Object warehouseId = basicPositionParam.getWarehouseId();
    	if (warehouseId!=null) {
			BasicWarehouse basicWarehouse = basicWarehouseService.getById(Integer.parseInt(warehouseId.toString()));
			basicPositionParam.setWarehouseName(basicWarehouse.getWarehouseName());
			basicPositionParam.setWarehouseNumber(basicWarehouse.getWarehouseNumber());
		}

    	BasicPositionParam param = new BasicPositionParam();
    	param.setWarehouseId(basicPositionParam.getWarehouseId());
    	param.setPositionNumber(basicPositionParam.getPositionNumber());
    	BasicPositionResult result = basicPositionService.findBySpec(param, null,null);
    	if (result != null) {
    		return ResponseData.error("The storage location number already exists");
		}

        //set 交付id
    	Long DeliverId = userService.getDeliverId();
    	if (DeliverId!=null) {
    		basicPositionParam.setDeliverId(DeliverId);
		}
    	basicPositionParam.setDeptId(userService.getDeptId());
        basicPositionParam.setPositionState("1");
        this.basicPositionService.add(basicPositionParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BasicPositionParam basicPositionParam) {
    	Object positionAreaId = basicPositionParam.getPositionAreaId();
    	if (positionAreaId!=null) {
			BasicArea bawBasicArea = basicAreaService.getById(Integer.parseInt(positionAreaId.toString()));
			basicPositionParam.setPositionAreaName(bawBasicArea.getAreaName());//库区名称
			basicPositionParam.setAreaNumber(bawBasicArea.getAreaNumber());
			basicPositionParam.setPositionFunction(bawBasicArea.getAreaFunction());//库区功能
			basicPositionParam.setPositionAreaType(bawBasicArea.getAreaType());//库区类型
		}
    	Object warehouseId = basicPositionParam.getWarehouseId();
    	if (warehouseId!=null) {
			BasicWarehouse basicWarehouse = basicWarehouseService.getById(Integer.parseInt(warehouseId.toString()));
			basicPositionParam.setWarehouseName(basicWarehouse.getWarehouseName());
			basicPositionParam.setWarehouseNumber(basicWarehouse.getWarehouseNumber());
		}

        this.basicPositionService.update(basicPositionParam);
        return ResponseData.success();
    }

    @Autowired
    private HxStorageStockService hxStorageStockService;

    /**
     * 编辑接口
     */
    @RequestMapping("/editItemStatus")
    @ResponseBody
    public ResponseData editItemStatus(BasicPositionParam basicPositionParam) {
    	if(ToolUtil.isNotEmpty(basicPositionParam.getPositionState())&&basicPositionParam.getPositionState().equals("2")) {
    		Integer hxcount = hxStorageStockService.lambdaQuery()
    		.eq(HxStorageStock::getPositionId, basicPositionParam.getId())
    		.count();
    		if(hxcount > 0) {
    			return ResponseData.error("There is inventory in the retail location! Cannot disable");
    		}
    	}
        this.basicPositionService.update(basicPositionParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BasicPositionParam basicPositionParam) {
        this.basicPositionService.delete(basicPositionParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     */
    @RequestMapping("/btnRevoke")
    @ResponseBody
    public ResponseData btnRevoke(Integer[] ids) {
    	for (Integer id : ids) {
    		BasicPositionParam basicPositionParam = new BasicPositionParam();
    		basicPositionParam.setId(id);
    		this.basicPositionService.delete(basicPositionParam);
		}
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BasicPositionParam basicPositionParam) {
        BasicPosition detail = this.basicPositionService.getById(basicPositionParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BasicPositionParam basicPositionParam,String condition ,Long WarehouseId) {
    	User user = userService.getcurrentUser();
    	basicPositionParam.setDeliverId(user.getDeliverId());
    	Long deptId = user.getDeptId();
        return this.basicPositionService.findPageBySpec(basicPositionParam,condition,deptId,WarehouseId,user.getOperateId());
    }

    /**
     * 查询列表
     *
     * @author zhucx
     * @Date 2023-08-15
     */
    @ResponseBody
    @RequestMapping("/listAll")
    public List<BasicPositionResult> listAll(BasicPositionParam basicPositionParam,String condition ,Long WarehouseId) {
    	User user = userService.getcurrentUser();
    	basicPositionParam.setDeliverId(user.getDeliverId());
    	Long deptId = user.getDeptId();
        return this.basicPositionService.findlistAllBySpec(basicPositionParam,condition,deptId,WarehouseId,user.getOperateId());
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/Querylist")
    public List<BasicPositionResult> Querylist(BasicPositionParam basicPositionParam) {
    	User user = userService.getcurrentUser();
    	basicPositionParam.setDeliverId(user.getDeliverId());
    	Long deptId = user.getDeptId();
        return this.basicPositionService.findListBySpec(basicPositionParam, null, deptId, 0L,user.getOperateId());
    }

    /**
     * 库容存量统计
     */
    @ResponseBody
    @RequestMapping("/Storagelist")
    public LayuiPageInfo Storagelist(BasicPositionParam basicPositionParam,String condition ,Long WarehouseId) {
    	Long deptId = userService.getDeptId();
        return this.basicPositionService.findStoragelistPageBySpec(basicPositionParam,condition,deptId,WarehouseId);
    }

}


